#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2021/4/21 12:00
# @Author : hedan
# @FileName：product_car_page.py
# @Software:PyCharm
import time

from lib.func import think_time
from lib.loggers import log
from public.App_Page import AppPage, BasePage


class Product_Car(BasePage):


    @think_time
    def go_product_home(self):
        self.find_text("选车").click()
        while not self.find_text("选车"):
            if self.find_text("选车"):
                self.back()
            time.sleep(0.5)

    @think_time
    def click_id(self, id):
        self.find_id(id).click()

    @think_time
    def click_text(self, text):
        self.find_text(text).click()

    @think_time
    def get_window(self,text):
        return self.gettitle_text(self.find_text(text))

    @think_time
    def get_id_text(self, id):
        '''
        通过id获取text
        :param id:
        :return:
        '''
        return self.gettitle_text(self.find_id(id))


    @think_time
    def click_xpath(self,xpath):
        return self.d.xpath(xpath).click()

    @think_time
    def inputtext(self,text):
        return self.d(focused=True).set_text(text)

    def is_exists(self, text):
        return self.d(text=text).get_text() == text

    @think_time
    def get_scorll(self):
        '''
        滑动一屏
        :return:
        '''
        self.d(scrollable=True).scroll()

    @think_time
    def swipe_to_left_filter(self):
        '''
        左滑--筛选
        :return:
        '''
        self.d.swipe(532, 1195, 104, 1195)


    @think_time
    def swipe_to_left_accessories(self):
        '''
        左滑--推荐配件
        :return:
        '''
        self.d.swipe(454, 1444, 58, 1444)

    @think_time
    def scrollable_one(self):
        '''滑动整屏'''
        self.d(scrollable=True).fling()

    @think_time
    def scrollable_up(self):
        '''
        向上滑动
        :return:
        '''
        self.d.swipe_ext("up")

    @think_time
    def scrollable_down(self):
        '''
        滑到最底端
        :return:
        '''
        self.d(scrollable=True).scroll.toEnd()

    @think_time
    def scrollable_top(self):
        '''
        滑到最顶端
        :return:
        '''
        self.d(scrollable=True).scroll.toBeginning()


    @think_time
    def scrollable_description(self,position):
        '''
        根据文本滑动找到某个特定元素
        :param position:
        :return:
        '''
        self.d(scrollable=True).scroll.to(text=position)

    @think_time
    def gohome_car(self):
        while not self.find_text("请输入车辆名称或品牌"):
            self.d.press("back")
            if self.find_text("选车"):
                if self.find_text("推荐配件"):
                    self.find_text("推荐配件").click()
                self.find_text("选车").click()
            time.sleep(0.3)

    @think_time
    def app_stop(self):
        time.sleep(1)
        return self.d.app_stop("com.truckhome.bbs")

    @think_time
    def like_text(self,text):
        self.d(textContains=text).click()
